package com.liuzh.deviceinfo.card;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.cardview.widget.CardView;
import b.e.b.a;
import c.d.a.a.b.i;
import c.d.a.a.c.f;
import c.d.a.a.f.b.e;
import c.d.a.a.j.g;
import c.h.a.d0.d;
import c.h.a.m0.h;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.liuzh.deviceinfo.view.circleprogress.ArcProgress;
import java.util.ArrayList;

public class RamUsageCard extends CardView {
    public ArcProgress j;
    public TextView k;
    public TextView l;
    public TextView m;
    public LineChart n;
    public boolean o = false;
    public d p = new d(getContext());

    public RamUsageCard(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0);
        d();
    }

    @SuppressLint({"SetTextI18n"})
    private void setupTotalRam(d dVar) {
        if (!this.o) {
            TextView textView = this.m;
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append((int) dVar.b);
            stringBuilder.append(" MB");
            textView.setText(stringBuilder.toString());
            this.o = true;
        }
    }

    public final void d() {
        setUseCompatPadding(true);
        int t = h.t(8.0f, getResources().getDisplayMetrics());
        this.e.set(t, t, t, t);
        ((a) CardView.i).c(this.g);
        FrameLayout.inflate(getContext(), 2131492934, this);
        this.j = (ArcProgress) findViewById(2131296816);
        this.k = (TextView) findViewById(2131296822);
        this.l = (TextView) findViewById(2131296817);
        this.n = (LineChart) findViewById(2131296696);
        this.m = (TextView) findViewById(2131296820);
        t = c.f.a.a.a.a.n(getContext(), 2130969401);
        this.n.setDrawGridBackground(false);
        this.n.getDescription().a = false;
        this.n.setBackgroundColor(0);
        f fVar = new f();
        for (c.d.a.a.f.b.d c0 : fVar.i) {
            c0.c0(t);
        }
        this.n.setData(fVar);
        this.n.getLegend().a = false;
        this.n.setTouchEnabled(false);
        this.n.getXAxis().a = false;
        this.n.getAxisLeft().a = false;
        i axisRight = this.n.getAxisRight();
        axisRight.o = 3;
        axisRight.e = t;
        axisRight.q = false;
        axisRight.d = g.d(9.0f);
    }

    public void e() {
        this.p.d();
        setupTotalRam(this.p);
        this.j.setProgress((int) this.p.e);
        float f = (float) this.p.d;
        this.k.setText(String.valueOf((int) f));
        this.l.setText(String.valueOf((int) this.p.c));
        f fVar = (f) this.n.getData();
        if (fVar != null) {
            int i = 0;
            c.d.a.a.f.b.d dVar = (e) fVar.c(0);
            if (dVar == null) {
                dVar = new c.d.a.a.c.g(null, "Dynamic Data");
                dVar.d = i.a.RIGHT;
                int n = c.f.a.a.a.a.n(getContext(), 2130969401);
                if (dVar.a == null) {
                    dVar.a = new ArrayList();
                }
                dVar.a.clear();
                dVar.a.add(Integer.valueOf(n));
                dVar.H = false;
                dVar.A = c.d.a.a.c.g.a.CUBIC_BEZIER;
                dVar.z = g.d(2.0f);
                dVar.j = false;
                fVar.b(dVar);
                fVar.i.add(dVar);
            }
            Entry entry = new Entry((float) dVar.i0(), f);
            if (fVar.i.size() > 0) {
                c.d.a.a.f.b.d dVar2 = (c.d.a.a.f.b.d) fVar.i.get(0);
                if (dVar2.m(entry)) {
                    i.a e0 = dVar2.e0();
                    float f2 = fVar.a;
                    float f3 = entry.a;
                    if (f2 < f3) {
                        fVar.a = f3;
                    }
                    if (fVar.b > f3) {
                        fVar.b = f3;
                    }
                    f2 = fVar.c;
                    float f4 = entry.c;
                    if (f2 < f4) {
                        fVar.c = f4;
                    }
                    if (fVar.d > f4) {
                        fVar.d = f4;
                    }
                    if (e0 == i.a.LEFT) {
                        if (fVar.e < f3) {
                            fVar.e = f3;
                        }
                        if (fVar.f > f3) {
                            fVar.f = f3;
                        }
                    } else {
                        if (fVar.g < f3) {
                            fVar.g = f3;
                        }
                        if (fVar.h > f3) {
                            fVar.h = f3;
                        }
                    }
                }
            } else {
                Log.e("addEntry", "Cannot add Entry because dataSetIndex too high or too low.");
            }
            fVar.a();
            this.n.j();
            this.n.setVisibleXRangeMaximum(20.0f);
            LineChart lineChart = this.n;
            float e = (float) fVar.e();
            c.d.a.a.j.h hVar = lineChart.t;
            c.d.a.a.j.f fVar2 = lineChart.f0;
            c.d.a.a.g.a aVar = (c.d.a.a.g.a) c.d.a.a.g.a.h.b();
            aVar.c = hVar;
            aVar.d = e;
            aVar.e = 0.0f;
            aVar.f = fVar2;
            aVar.g = lineChart;
            hVar = lineChart.t;
            if (hVar.d > 0.0f && hVar.c > 0.0f) {
                i = 1;
            }
            if (i != 0) {
                lineChart.post(aVar);
            } else {
                lineChart.E.add(aVar);
            }
        }
    }
}
